window.addEventListener('DOMContentLoaded',function(){
    ajax_get('https://www.aulence.com/data/hardware-info.json',function(data){
        const showDataUl = document.querySelector('.show-data');
        let i = 0;
     for(let name in data){
         const item = document.createElement('li');
         item.textContent = name;
         item.index = i++;
         item.onclick = function(){
             alert(this.index +":" +  data[this.textContent]);
         }
         showDataUl.appendChild(item);
     }
    });
});


/**
 * 请求数据（GET）
 * @param { String } url 请求地址
 * @param { Function } callback 成功回调函数
 */
 function ajax_get(url, callback){
     const xhr = new XMLHttpRequest();
     xhr.open('GET',url);
     xhr.send();
     xhr.onreadystatechange = function(){
       
             if(xhr.readyState ===4){
                 if(xhr.status ===200){
                     const res = JSON.parse(xhr.response);
                     callback(res);
                 }
             }
         }
     }


 